package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.entity.Activity;
import com.baomidou.springboot.mapper.ActivityMapper;
import com.baomidou.springboot.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 专题活动 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public void save(Activity activity) {
        activity.setCreateDate(new Date());
        activityMapper.insert(activity);
    }

    @Override
    public void delete(String id) {
        activityMapper.deleteById(id);
    }

    @Override
    public Activity edit(String id) {
        return activityMapper.selectById(id);
    }

    @Override
    public void update(Activity activity) {
        activity.setModifyDate(new Date());
        activityMapper.updateById(activity);
    }

    @Override
    public Activity view(String id) {
        return activityMapper.selectById(id);
    }

    @Override
    public Page<Activity> list(Page<Activity> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Activity> activityList = activityMapper.findByDateDesc(page, search);
        page.setRecords(activityList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        activityMapper.deleteBatchIds(ids);
    }

    @Override
    public List<Activity> findByLimit(Integer limit) {
        return activityMapper.findByLimit(limit);
    }
}
